package com.slkj.shilixiaoyuanapp.entity;

import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.slkj.shilixiaoyuanapp.data.UserRequest;

import org.w3c.dom.Comment;

import java.util.List;

/**
 * Created  on 2018-08-13
 *
 * @author 唐开阔
 * @describe 社区数据实体
 */
public class CommunityEntity implements MultiItemEntity {
    public static final int TYPE_COMMON = 1;
    private int type = 1;
    private int isTeacher;
    /**
     * images : ["http://47.106.8.136:8082/images/school3/classDynamic/1535077276198.jpeg"]
     * address : 绿地集团西南总部营销中心
     * intime : 2018-08-24 10:21:16
     * headImg : http://47.106.8.136:8082/images/school3/head/1533869873955.png
     * isDelete : false
     * nickName : 人好
     * body : 提醒谁看通知
     * userId : 2
     * fabulousUser : [{"id":2,"name":"人好"}]
     * isFabulous : 1
     * comment : []
     * id : 25
     * fabulous : 1
     */

    private String address;
    private String intime;
    private String headImg;
    private boolean isDelete;
    private String nickName;
    private String body;
    private int userId;
    private int isFabulous;
    private int id;
    private int fabulous;
    private List<String> images;
    private List<FabulousUser> fabulousUser;
    private List<Comment> comment;

    @Override
    public int getItemType() {
        return type;
    }

    public boolean isTeacher() {
        return isTeacher == 2;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getIntime() {
        return intime;
    }

    public void setIntime(String intime) {
        this.intime = intime;
    }

    public String getHeadImg() {
        return headImg;
    }

    public void setHeadImg(String headImg) {
        this.headImg = headImg;
    }

    public boolean isIsDelete() {
        return isDelete;
    }

    public void setIsDelete(boolean isDelete) {
        this.isDelete = isDelete;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public int getIsFabulous() {
        return isFabulous;
    }

    public void setIsFabulous(int isFabulous) {
        this.isFabulous = isFabulous;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getFabulous() {
        return fabulous;
    }

    public void setFabulous(int fabulous) {
        this.fabulous = fabulous;
    }

    public List<String> getImages() {
        return images;
    }

    public void setImages(List<String> images) {
        this.images = images;
    }

    public List<FabulousUser> getFabulousUser() {
        return fabulousUser;
    }

    public void setFabulousUser(List<FabulousUser> fabulousUser) {
        this.fabulousUser = fabulousUser;
    }
    public boolean isFabulous(){
        return isFabulous == 1;
    }

    /**
     * 点赞或者取消点赞成功
     */
    public void changeFabulous(){
        //取消点赞成功
        UserEntity.User user = UserRequest.getInstance().getUser().getUser();
        if (isFabulous == 1){
            isFabulous = 0;
            int pos = -1;
            for (int i = 0; i < fabulousUser.size(); i++) {
                FabulousUser entity = fabulousUser.get(i);
                if (entity.getId() == user.getId()){
                    pos = i;
                    break;
                }
            }
            if (pos != -1) {
                fabulousUser.remove(pos);
            }

        }
        //新增点赞成功
        else {
            isFabulous = 1;
            fabulousUser.add(new FabulousUser(user.getId(),user.getUNickName()));
        }
    }

    /**
     * 评论或者回复成功
     * @param str
     * @param comment
     */
    public void commentSuccess(String str,CommunityEntity.Comment comment){
        //回复
        if(comment == null){

        }
        //回复评论
        else {

        }
    }
    public List<Comment> getComment() {
        return comment;
    }

    public void setComment(List<Comment> comment) {
        this.comment = comment;
    }

    public static class Comment {

        /**
         * nickName : 人好
         * commentUser :
         * comment : 你好
         * id : 4
         * type : 1 //1评论，2回复
         * userId : 2
         * commentUserId : 0
         */

        private String nickName;
        private String commentUser;
        private String comment;
        private int id;
        private int type;
        private int userId;
        private String commentUserId;



        public String getNickName() {
            return nickName;
        }

        public void setNickName(String nickName) {
            this.nickName = nickName;
        }

        public String getCommentUser() {
            return commentUser;
        }

        public void setCommentUser(String commentUser) {
            this.commentUser = commentUser;
        }

        public String getComment() {
            return comment;
        }

        public void setComment(String comment) {
            this.comment = comment;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public int getType() {
            return type;
        }

        public void setType(int type) {
            this.type = type;
        }

        public int getUserId() {
            return userId;
        }

        public void setUserId(int userId) {
            this.userId = userId;
        }

        public String getCommentUserId() {
            return commentUserId;
        }

        public void setCommentUserId(String commentUserId) {
            this.commentUserId = commentUserId;
        }
    }


    public static class FabulousUser {
        /**
         * id : 2
         * name : 人好
         */

        private int id;
        private String name;

        public FabulousUser(int id, String name) {
            this.id = id;
            this.name = name;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}
